﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Comom.Project.ControllerCom;
using Dhtl.Service.IService;
using dai_hoc_tuong_lai.Areas.Admin.Models;

namespace dai_hoc_tuong_lai.Controllers
{
    public class TinTucController : UTController
    {
        //
        // GET: /TinTuc/
        private readonly INews _iNews;
        private readonly int PageSize = 15;

        public TinTucController(INews iNews)
        {
            this._iNews = iNews;
        }

        public ActionResult ListNewsTop()
        {

            var listEntity = _iNews.ListNewsOfTop();
            List<NewsModel> model = new List<NewsModel>();
            try
            {
                foreach (var item in listEntity)
                {
                    NewsModel ml = new NewsModel();
                    NewsModel.MapFrom(item, ref  ml);
                    model.Add(ml);
                }
            }
            catch { }

            return PartialView("_ListNewsTop", model);

        }

        public ActionResult List()
        {

            var listEntity = _iNews.List();
            List<NewsModel> model = new List<NewsModel>();
            try
            {
                if(listEntity.Count () > 10 ) listEntity = listEntity.Take(10).ToList();
                foreach (var item in listEntity)
                {
                    NewsModel ml = new NewsModel();
                    NewsModel.MapFrom(item, ref  ml);
                    model.Add(ml);
                }
            }
            catch { }

            return PartialView("_List", model);

        }

        public ActionResult ListOnIndex()
        {
            var listEntity = _iNews.List();
            List<NewsModel> model = new List<NewsModel>();
            try
            {
                foreach (var item in listEntity)
                {
                    NewsModel ml = new NewsModel();
                    NewsModel.MapFrom(item, ref  ml);
                    model.Add(ml);
                }
            }
            catch { }

            return PartialView("_ListOnIndex", model);
        }

        public ActionResult NewsDetails(int id, string name)
        {
            var entity = _iNews.GetById(id);
            NewsModel ml = new NewsModel();
            NewsModel.MapFrom(entity, ref  ml);
            return View(ml);
        }

        public ActionResult Index()
        {
            return View();
        }

    }
}
